<template>
  <div class="reward">
    <el-form
      ref="form"
      :inline="true"
      class="demo-form-inline"
      :model="queryParams"
    >
      <el-form-item label="活动周期" prop="stageId">
        <el-select
          v-model="queryParams.stageId"
          size="small"
          clearable
          placeholder="请选择"
          style="width:240px"
        >
        <template  v-for="item in [{ id: '', flowerStageName: '全部', stageStatus: 'OTHER'},...activeStatus]">
          <el-option
            v-if="item.stageStatus !== 'NOT_STARTED' && item.stageStatus !== 'NOT_START' "
            :key="item.id"
            :label="item.flowerStageName"
            :value="item.id"
          ></el-option>
        </template>
          
        </el-select>
      </el-form-item>

      <el-form-item label="查找" prop="dpAccount" class="right">
        <el-input
          clearable
          v-model="queryParams.dpAccount"
          placeholder="请输入大鹏号"
          size="small"
          class="numberInput"
        ></el-input>
      </el-form-item>
      <el-form-item class="s-btn">
        <el-button type="success" icon="el-icon-search" @click="toSearch()">
          查询
        </el-button>
        <el-button type="success" plain @click="reset"> 重置 </el-button>
      </el-form-item>
    </el-form>
    <!-- 按钮 -->
    <div class="btn-box">
      <el-row>
        <el-col :span="2" :offset="20">
          <el-button type="success" size="medium" @click="exportFile"
            >导出</el-button
          >
          <freshCom @searchList="searchList"></freshCom>
        </el-col>
      </el-row>
    </div>
    <!-- table -->
    <el-table
      id=""
      v-loading="loading"
      :data="tableData"
      border
      style="width: 100%"
      max-height="700"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="index" label="序号" width="100" align="center" />
      <el-table-column
        label="用户昵称"
        align="left"
        prop="user.userName"
        width="180"
      />
      <el-table-column
        label="电话"
        align="left"
        prop="user.mobile"
        width="210"
      />
      <el-table-column
        label="大鹏号"
        align="left"
        prop="user.dpAccount"
        width="180"
      />
      <el-table-column
        label="活动名称"
        align="left"
        prop="activityName"
        width="180"
      />
      <el-table-column label="活动周期" align="left" prop="stagesNames">
        <template slot-scope="scope">
          <div style="text-align: left">
            <span>{{ scope.row.stagesNames }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="奖励明细"
        align="left"
        prop="awardsDetails"
        width="210"
      >
        <template slot-scope="scope">
          <div style="text-align: left">
            <span>{{ scope.row.awardsDetails }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="名次" align="center" prop="rank" width="100">
        <template slot-scope="scope">
          <div style="text-align: center">
            <span>{{ scope.row.rank }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="奖励时间"
        align="center"
        prop="createdTime"
        width="210"
      ></el-table-column>
    </el-table>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
  </div>
</template>

<script>
import {
  getStages,
  getRecordsList,
  recordsExport,
} from '@/api/flowerActive/partakeReward/index'
export default {
  data() {
    return {
      queryParams: {
        dpAccount: '', // 查找大鹏用户
        stageId: '', // 活动周期
      },
      activeStatus: [],
      // 加载loading状态
      loading: true,
      //  loading: true,
      // 总条数
      total: 0,
      // 分页数据
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10, // 页面显示条数
      },
      // table参数
      tableData: [],
      // 非多个禁用
      multiple: true,
      // 存放选中表格用户数量
      ids: [],
    }
  },
  async created() {
    await this.getStages(this.$route.query.id)
  },
  methods: {
    // 活动周期
    getStages(id) {
      getStages(id, (res) => {
        this.activeStatus = res
      })
    },
    // 顶部查询功能
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    },
    // 获取列表
    searchList() {
      let id = this.$route.query.id;
      let params = {
        ...this.searchParams,
        ...this.queryParams,
      }
      getRecordsList(id, params, (res) => {
        if (res.rows) {
          this.tableData = res.rows
          this.total = res.total
        }
        this.loading = false
      })
    },
    /* 导出 */
    exportFile(type) {
      this.$confirm('确定导出奖励记录吗？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          let url = recordsExport({id:this.$route.query.id})
          let params = Object.assign({}, this.queryParams, this.searchParams)
          params.pageSize = 10000000
          this.downFile('get', url, params, '奖励记录')
        })
        .catch(() => {})
    },
    handleSelectionChange(selection) {
      // 选中表格用户数量
      this.ids = selection.map((item) => item.id)
      this.multiple = !selection.length
    },

    /* 重置 */
    reset() {
      this.$refs['form'].resetFields()
    },
  },
}
</script>

<style lang="less" scoped>
.reward {
  margin: 20px 30px 20px 30px;
  .right {
    margin-left: 40px !important;
  }
  .btn-box {
    margin-bottom: 30px;
  }
}
</style>